﻿package com.taobao.top
{
	public class TOPUtil
	{
		public function TOPUtil()
		{
		}
		
		/**
		 * 将数组转化为以逗号分隔的字符串
		 * @param arr 预处理的数组
		 * @return 以逗号分隔的字符串
		 * 
		 */		
		public static function StringArrayToStringWidthComma(arr:Array):String
		{
			var str:String = "";
			for each(var s:String in arr)
			{
				str+=(s+",");
			}
			//剔除最后一个逗号
			str=str.substr(0,str.length-1);
			return str;
		}
		
		/**
		 * 获取符合API的日期字符串 
		 * @param date 预处理的Date对象
		 * @return 处理后的字符串
		 * 
		 */		
		public static function getCustomDateString(date:Date):String
		{
			//2009-07-08 22:14:20
			var dateStr:String = "";
			dateStr+=date.fullYear+"-";
			
			if(date.month<9)
			{
				dateStr+="0"+(date.month+1)+"-";
			}else
			{
				dateStr+=(date.month+1)+"-";
			}
			
			if(date.date<=9)
			{
				dateStr+="0"+date.date+" ";
			}else
			{
				dateStr+=date.date+" ";
			}
			
			if(date.hours<=9)
			{
				dateStr+="0"+date.hours+":";
			}else
			{
				dateStr+=date.hours+":";
			}
			
			if(date.minutes<=9)
			{
				dateStr+="0"+date.minutes+":";
			}else
			{
				dateStr+=date.minutes+":";
			}
			
			if(date.seconds<=9)
			{
				dateStr+="0"+date.seconds;
			}else
			{
				dateStr+=date.seconds;
			}
			return dateStr;
		}
		
		/**
		 *  
		 * @param dateStr
		 * @return 
		 * 
		 */		
		public static function getCustomDate(dateStr:String):Date
		{
			if (dateStr == null)
			{
				return null;
			}
			var tempArr:Array = dateStr.split(" ");
			if (tempArr.length == 0)
			{
				return null;
			}else
			{
				var dateArr:Array = String(tempArr[0]).split("-");
				var timeArr:Array = String(tempArr[1]).split(":");
				var year:int, month:int, date:int, hour:int, minute:int, second:int;
				year = int(dateArr[0]);
				month = int(dateArr[1]);
				date = int(dateArr[2]);
				
				hour = int(timeArr[0]);
				minute = int(timeArr[1]);
				second = int(timeArr[2]);
				return new Date(year, month, date, hour, minute, second);
			}
			return null;
		}
	}
}